# -*- coding: utf-8 -*-

import cairo

WIDTH = 80
HEIGHT = 100

def loadImage(ctx, filename, x, y, operator=None):
    if operator is not None:
        ctx.set_operator(operator)
    img = cairo.ImageSurface.create_from_png(filename)
    ctx.set_source_surface(img, x, y)
    ctx.paint()

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
loadImage(ctx, 'bg.png', 0, 0)
loadImage(ctx, 'sunny.png', 10, 20)

ctx.set_operator(cairo.OPERATOR_OVER)
ctx.set_source_rgba(0.43,0.47,0.506,0.8)

ctx.move_to(10, 80)
ctx.line_to(70, 80)
ctx.set_line_width(20)
ctx.set_line_cap(cairo.LINE_CAP_ROUND)
ctx.stroke()


ctx.set_operator(cairo.OPERATOR_OVER)
ctx.select_font_face("Sans")
ctx.set_font_size(13)
ctx.set_source_rgb(1.0, 1.0, 1.0)
x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents("77/59°F")
ctx.move_to((80 - x_bearing - width) / 2, 85)
ctx.show_text("77/59°F")

ctx.set_operator(cairo.OPERATOR_OVER)
ctx.set_source_rgba(0.43,0.47,0.506,0.8)
ctx.move_to(20, 15)
ctx.line_to(60, 15)
ctx.set_line_width(20)
ctx.set_line_cap(cairo.LINE_CAP_ROUND)
ctx.stroke()

ctx.set_operator(cairo.OPERATOR_OVER)
ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
ctx.set_font_size(15)
ctx.set_source_rgba(1.0,1.0,1.0)
x_bearing, y_bearing, width, height, x_advance, y_advance = ctx.text_extents("73°F")
ctx.move_to((80 - x_bearing - width) / 2, 20)
ctx.show_text("73°F")
surface.write_to_png("weather.png")
